class Rank extends egret.DisplayObjectContainer {

	/****************************** 资源与loading配置 ***************************/

    static resUrl: string   = "resource/default.res.json";
    static resRoot: string  = "resource/";
    static resGroup: string = "rank";
    static loading: any     = LoadingUI;


	public constructor() {
		super();
		this.$addListener(egret.Event.ADDED_TO_STAGE,this.createGameScene,this);
	}
	private createGameScene(){
		//背景
		var backgroundImg = creatImg("blue_bg_png");
		this.addChild(backgroundImg);
		//创建背景图片
		var shuiwen = creatImg("shuiwen_png");
		shuiwen.width = 640;
		shuiwen.height = 1136;
		shuiwen.scaleX = 1.04;
		shuiwen.scaleY = 1.1;
		shuiwen.anchorOffsetX = this.stage.$stageWidth * .5;
		shuiwen.anchorOffsetY = this.stage.$stageHeight * .5;
		shuiwen.x = shuiwen.width * .5;
		shuiwen.y = shuiwen.height * .5;
		this.addChild(shuiwen);
		var move = egret.Tween.get(shuiwen, { loop: true });
		move.to({ x: shuiwen.width * .5 - 5,y: shuiwen.height * .5 - 60}, 7000).wait(500).to({ x: shuiwen.width * .5,y: shuiwen.height * .5 }, 7000);
		//gold背景
		var goldBg =  creatImg('rank_bg_png');
		goldBg.width = 208;
		goldBg.height = 360;
		goldBg.x = 218;
		this.addChild(goldBg);
		//头像
		var portrait =  creatImg('touxiang_png');
		portrait.width = 108;
		portrait.height =  108;
		portrait.x = 86;
		portrait.y = 198;
		this.addChild(portrait);
		//Name
		var name = createWord(90,310,46,0xffffff,"Amy");
		this.addChild(name);
		var rankingTitle = createWord(263,200,28,0xff4c22,"全国排名");
		this.addChild(rankingTitle);
		var ranking = createWord(263,240,68,0xff4c22,"498");
		this.addChild(ranking);
		var time = createWord(480,220,26,0xffffff,"time");
		this.addChild(time);

		/***************时间**************/
		var num = ScenesMgmt.self.prevScene.getRecord();
		var timeCount = createWord(435,260,42,0xffffff,num,true);
		this.addChild(timeCount);

		//Title
		var titleBg = creatImg('title_bg_03_png');
		titleBg.x = 64;
		titleBg.y = 384;
		this.addChild(titleBg);
		var title = createWord(100,410,36,0xff4c22,"指尖自由泳全国前10排行榜");
		this.addChild(title);

		//按钮
		var buttonOne =  creatText("晒战绩",42,0xfe3c63,"show_03_png",160,91);
		var buttonTwo =  creatText("前往领奖台抽奖",42	,0xfe3c63,"show2_05_png",316,91)
		this.addChild(buttonOne);
		this.addChild(buttonTwo);
		let n = window.innerWidth / this.stage.stageWidth;
		let comStageH = this.stage.stageHeight*n;
		let clipH = comStageH - window.innerHeight;
		if(clipH<0) clipH = 0;
		buttonOne.x = 60;
		buttonOne.y = this.stage.stageHeight - 145 - clipH/(2*n);
		buttonTwo.x = 260;
		buttonTwo.y = this.stage.stageHeight - 145 - clipH/(2*n);

		/*************晒战绩弹窗************ */
		buttonOne.touchEnabled = true;
		buttonOne.addEventListener(egret.TouchEvent.TOUCH_BEGIN,function(){
			egret.Tween.get(buttonOne).to({alpha:.8},100);
			 //创建分享弹出层
            let shape: egret.DisplayObjectContainer = Dialogs.share("分享一下\n晒出战线~");
            //打开分享弹出层
            Effect.fadeIn(shape, this.stage);
		},this)
		buttonOne.addEventListener(egret.TouchEvent.TOUCH_END,function(){
			egret.Tween.get(buttonOne).to({alpha:1},100);
		},this)

		/*************跳转手机验证************ */
		buttonTwo.touchEnabled = true;
		buttonTwo.addEventListener(egret.TouchEvent.TOUCH_BEGIN,function(){
			egret.Tween.get(buttonTwo).to({alpha:.8},100);
			 ScenesMgmt.self.changeScene(Confirmation);
		},this);
		buttonTwo.addEventListener(egret.TouchEvent.TOUCH_END,function(){
			egret.Tween.get(buttonTwo).to({alpha:1},100);
		},this);
		
		//滚动容器
		let scrollView:egret.ScrollView = new egret.ScrollView();
		let scrollCon: egret.Sprite = new egret.Sprite();
		scrollView.cacheAsBitmap = true;
		scrollView.setContent(scrollCon);
		this.addChild(scrollView);
		//设置滚动视图样式
		scrollView.width = 490;
		scrollView.height = 395;
		scrollView.x = 78;
		scrollView.y = 485;
		//排行榜信息
		var rank = [
			{x:15,y:15,rankNum:"1",cirLineCor:"0xfac855",cirBgCor:"0xfff530",url:"touxiang_png",name:"Amy",time:"10.00"},
			{x:15,y:115,rankNum:"2",cirLineCor:"0x808080",cirBgCor:"0xe6e6e6",url:"touxiang_png",name:"Amy",time:"11.00"},
			{x:15,y:215,rankNum:"3",cirLineCor:"0xb08579",cirBgCor:"0xd0aea3",url:"touxiang_png",name:"Amy",time:"12.00"},
			{x:15,y:315,rankNum:"4",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"13.00"},
			{x:15,y:415,rankNum:"5",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"14.00"},
			{x:15,y:515,rankNum:"6",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"15.00"},
			{x:15,y:615,rankNum:"7",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"16.00"},
			{x:15,y:715,rankNum:"8",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"17.00"},
			{x:15,y:815,rankNum:"9",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"18.00"},
			{x:15,y:915,rankNum:"10",cirLineCor:"0xfffefd",cirBgCor:"0xfffefd",url:"touxiang_png",name:"Amy",time:"19.00"}
		];
		for(var i=0;i<rank.length;i++){
			scrollCon.addChild(createRank(rank[i].x,rank[i].y,rank[i].rankNum,rank[i].cirLineCor,rank[i].cirBgCor,rank[i].url,rank[i].name,rank[i].time));
	}
	}
}